package com.ruoyi.system.util;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.config.ServerConfig;
import com.ruoyi.common.utils.file.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Component
public class FileUtil {

    private static final String BASE_PATH = "http://127.0.0.1:8080";

    public static String savePhoto(MultipartFile photo) throws IOException {
        String filePath = RuoYiConfig.getUploadPath();
        String fileName = FileUploadUtils.upload(filePath, photo);
        String url = BASE_PATH + fileName;
//        // 生成唯一文件名
//        String originalFileName = photo.getOriginalFilename();
//        String fileExtension = originalFileName.substring(originalFileName.lastIndexOf("."));
//        String newFileName = UUID.randomUUID().toString() + fileExtension;
//
//        // 保存文件到指定目录
//        String filePath = RuoYiConfig.getUploadPath() + newFileName;
//        File dest = new File(filePath);
//        photo.transferTo(dest);

        return url;
    }
}
